import { CopyInfoPanelBase } from "../CopyInfoPanelBase";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { Language } from "../../../../../extend/language/Language";
import { SGuildStruggleProcess } from "../../../../../Message/Public/SGuildStruggleProcess";
import { CopyUtil } from "../CopyUtil";
import { BossConfig } from "../../../resource/BossConfig";
import { ItemConfig } from "../../../resource/ItemConfig";
import { SecTimer } from "../../../../../com/gengine/core/frame/SecTimer";
import { TimerType } from "../../../../../com/gengine/core/frame/TimerType";
import { RemainTimeTool } from "../../award/RemainTimeTool";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { ClockManager } from "../../../manager/ClockManager";
import { ObjCreate } from "../../common/ObjCreate";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { Cache } from "../../../cache/Cache";
import { SGuildStruggleInfo } from "../../../../../Message/Public/SGuildStruggleInfo";
import { CopyConfig } from "../../../resource/CopyConfig";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { TGuildStruggleConfig } from "../../../../../Message/Db/Tables/TGuildStruggleConfig";
type int = number;
//class GuildCopyInfoPanel
    
    export  class GuildCopyInfoPanel extends CopyInfoPanelBase
    {
        constructor()
        {
            super();
            return;
        }

        /* internal  */resize(): void
        {
            var loc1=0;
            loc1 = 5;
            this._modeLabel.y = loc1;
            loc1 = loc1 + this._modeLabel.height;
            this._timeLabel.y = loc1;
            loc1 = loc1 + this._timeLabel.height;
            this._fastGuild.y = loc1;
            loc1 = loc1 + this._fastGuild.height;
            this._condition.y = loc1;
            loc1 = loc1 + this._condition.height;
            this._expLabel.y = loc1;
            loc1 = loc1 + this._expLabel.height;
            this._contribution.y = loc1;
            loc1 = loc1 + this._contribution.height;
            this._tips.y = loc1;
            loc1 = loc1 + this._tips.height;
            _bg.height = _bodySp.height + 10;
            return;
        }

        /* internal  */updateProcess(): void
        {
            this._condition.htmlText = HTMLUtil.addColor(Language.getString(60412), "#FFFF00") + "\n" + this.getConditionDesc(this._process);
            return;
        }

        /* internal  */getConditionDesc(arg1: SGuildStruggleProcess): string
        {
            var loc2=0;
            var loc3=0;
            var loc4=null;
            var loc5=null;
            var loc6=null;
            var loc7=null;
            var loc8=false;
            var loc1="";
            if (this._info) 
            {
                loc4 = "";
                var loc9=this._info.layer;
                switch (loc9) 
                {
                    case 1:
                    {
                        loc6 = CopyUtil.getGuildCopyBossList(this._config);
                        loc2 = 0;
                        while (loc2 < loc6.length) 
                        {
                            loc5 = loc6[loc2];
                            loc3 = arg1 ? this.getKillBossNum(loc5["bossCode"], arg1.killBosses) : 0;
                            loc4 = this.getColor(loc3, loc5["bossNum"]);
                            loc1 = loc1 + (Language.getStringByParam(60422, BossConfig.instance.getInfoByName(loc5["bossCode"]).name) + "  " + HTMLUtil.addColor(loc3 + "/" + loc5["bossNum"], loc4));
                            if (loc2 % 2 != 1) 
                            {
                                loc1 = loc1 + "\t";
                            }
                            else 
                            {
                                loc1 = loc1 + "\n";
                            }
                            ++loc2;
                        }
                        break;
                    }
                    case 2:
                    {
                        loc7 = CopyUtil.getGuildCopyItemList(this._config);
                        loc2 = 0;
                        while (loc2 < loc7.length) 
                        {
                            loc5 = loc7[loc2];
                            loc3 = arg1 ? this.getCollectItemNum(loc5["itemCode"], arg1.collectItems) : 0;
                            loc1 = loc1 + (Language.getStringByParam(60417, ItemConfig.instance.getInfoByCode(loc5["itemCode"]).item.name) + "  " + loc3 + "/" + loc5["itemNum"]);
                            loc1 = loc1 + "\n";
                            ++loc2;
                        }
                        break;
                    }
                    case 3:
                    {
                        if (!this._leftTimer) 
                        {
                            this._leftTimer = new SecTimer();
                            this._leftTimer.addListener(TimerType.ENTERFRAME, this.onLeftTimerEnterFrame);
                        }
                        if (this._info && !(this._leftTime == this._info.leftTime)) 
                        {
                            this._leftTime = this._info.leftTime;
                            this._leftTimer.repeatCount = this._leftTime;
                        }
                        this._leftTimer.start();
                        loc1 = loc1 + ("\t" + Language.getString(60415) + RemainTimeTool.getRemainTimeBySeconds(this._leftTimer.repeatCount) + "\n");
                        loc8 = true;
                        loc6 = CopyUtil.getGuildCopyBossList(this._config);
                        loc2 = 0;
                        while (loc2 < loc6.length) 
                        {
                            loc5 = loc6[loc2];
                            loc3 = arg1 ? this.getKillBossNum(loc5["bossCode"], arg1.killBosses) : 0;
                            loc4 = this.getColor(loc3, loc5["bossNum"]);
                            if (loc3 < loc5["bossNum"]) 
                            {
                                loc8 = false;
                            }
                            loc1 = loc1 + ("\t" + Language.getStringByParam(60422, BossConfig.instance.getInfoByName(loc5["bossCode"]).name) + "  " + HTMLUtil.addColor(loc3 + "/" + loc5["bossNum"], loc4));
                            if (loc2 % 2 == 1) 
                            {
                                loc1 = loc1 + "\n";
                            }
                            ++loc2;
                        }
                        if (this._info.isLayerEnd && this._leftTimer.running) 
                        {
                            this.stopOpenTimer();
                            this.updateTimeLabel(this._info.totalTime, true, loc8);
                            this._leftTimer.stop();
                        }
                        break;
                    }
                    default:
                    {
                        if (!(this._info.layer == 3) && this._leftTimer && this._leftTimer.running) 
                        {
                            this._leftTimer.reset();
                            this._leftTimer.stop();
                        }
                        break;
                    }
                }
            }
            return loc1;
        }

        /* internal  */getColor(arg1: int, arg2: int): string
        {
            if (arg1 >= arg2) 
            {
                return GlobalStyle.color5;
            }
            return GlobalStyle.color7;
        }

        /* internal  */getKillBossNum(arg1: int, arg2: Array<any>): int
        {
            var loc1=null;
            if (arg2) 
            {
                var loc2=0;
                var loc3=arg2;
                for(loc1 of loc3) 
                {
                    if (loc1.code != arg1) 
                    {
                        continue;
                    }
                    return loc1.num;
                }
            }
            return 0;
        }

        /* internal  */getCollectItemNum(arg1: int, arg2: Array<any>): int
        {
            var loc1=null;
            if (arg2) 
            {
                var loc2=0;
                var loc3=arg2;
                for(loc1 of loc3) 
                {
                    if (loc1.code != arg1) 
                    {
                        continue;
                    }
                    return loc1.num;
                }
            }
            return 0;
        }

        /* internal  */onLeftTimerEnterFrame(arg1: SecTimer): void
        {
            this.updateProcess();
            return;
        }

        /* internal  */updateOpenTime(): void
        {
            if (!this._openTimer) 
            {
                this._openTimer = new SecTimer();
                this._openTimer.addListener(TimerType.ENTERFRAME, this.onOpenTimerEnterframe);
            }
            var loc1=(ClockManager.instance.nowDate.time - this._info.openDt.time) / 1000;
            this._openTimer.currentCount = loc1 < 0 ? 0 : loc1;
            this._openTimer.start();
            return;
        }

        /* internal  */onOpenTimerEnterframe(arg1: SecTimer): void
        {
            this.updateTimeLabel(arg1.currentCount);
            return;
        }

        /* internal  */updateTimeLabel(arg1: int, arg2: Boolean=false, arg3: Boolean=true): void
        {
            var loc1="";
            if (arg2) 
            {
                if (arg3) 
                {
                    loc1 = Language.getString(60073);
                }
                else 
                {
                    loc1 = Language.getString(60429);
                }
            }
            this._timeLabel.htmlText = HTMLUtil.addColor(Language.getString(60410), "#FFFF00") + HTMLUtil.addColor(RemainTimeTool.getRemainTimeBySeconds(arg1), "#FE7800") + loc1;
            return;
        }

        /* internal  */stopOpenTimer(): void
        {
            if (this._openTimer && this._openTimer.running) 
            {
                this._openTimer.stop();
            }
            return;
        }

        public clean(): void
        {
            if (this._openTimer) 
            {
                this._openTimer.dispose(false);
                this._openTimer = null;
            }
            if (this._leftTimer) 
            {
                this._leftTimer.dispose(false);
                this._leftTimer = null;
            }
            return;
        }

        public getContributePoint(): Object /* flash.geom.Point */
        {
            return this.localToGlobal(new Object /* flash.geom.Point */(this._contribution.x + this._contribution.textWidth / 2, this._contribution.y + 10));
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this._modeLabel = ObjCreate.createGTextField("", _left, 25, 235, 20, _bodySp, new GTextFormat(FontUtil.songtiName, 14, 16776960, true));
            this._modeLabel.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._timeLabel = ObjCreate.createGTextField(Language.getString(60410), _left, 25, 235, 20, _bodySp, new GTextFormat(FontUtil.songtiName, 13.3, 16776960, true));
            this._timeLabel.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._fastGuild = ObjCreate.createGTextField("", _left, 25, 235, 20, _bodySp);
            this._fastGuild.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._condition = ObjCreate.createGTextField("", _left, 25, 235, 20, _bodySp, new GTextFormat(FontUtil.songtiName, 12, GlobalStyle.color1Uint, null, null, null, null, null, flash.text.TextFormatAlign.LEFT, null, null, -19, 3));
            this._condition.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._condition.mouseWheelEnabled = false;
            this._expLabel = ObjCreate.createGTextField("", _left, 25, 235, 20, _bodySp, new GTextFormat(FontUtil.songtiName, 13.2, GlobalStyle.color5Uint, true));
            this._expLabel.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._contribution = ObjCreate.createGTextField("", _left, 25, 235, 20, _bodySp, new GTextFormat(FontUtil.songtiName, 13.2, GlobalStyle.color5Uint, true));
            this._contribution.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._tips = ObjCreate.createGTextField("", _left, 25, 235, 20, _bodySp, new GTextFormat(FontUtil.songtiName, 12, 16777215, null, null, null, null, null, flash.text.TextFormatAlign.LEFT, null, null, -19, 3));
            this._tips.wordWrap = true;
            this._tips.multiline = true;
            this._tips.mouseWheelEnabled = false;
            this._tips.autoSize = flash.text.TextFieldAutoSize.LEFT;
            return;
        }

        public /* override */ updateInfos(arg1): void
        {
            var loc1=Cache.instance.copy.guildStruggleInfo;
            var loc2=Cache.instance.copy.guildStruggleProcess;
            this.updateStruggleInfo(loc1);
            this.updateProcessInfo(loc2);
            return;
        }

        public updateStruggleInfo(arg1: SGuildStruggleInfo): void
        {
            var loc1=false;
            if (!this._info || !(this._info.openDt.time == arg1.openDt.time)) 
            {
                loc1 = true;
            }
            this._info = arg1;
            if (this._info) 
            {
                this._config = CopyConfig.instance.getGuildStruggleConfig(this._info.layer, this._info.difficulty);
                this._modeLabel.htmlText = CopyUtil.getDifficultyDef(this._info.difficulty) + "-" + Language.getStringByParam(60414, this._info.layer) + "（" + this._config.name + "）";
                this.updateExp();
                this.updateContribute();
                if (loc1) 
                {
                    this.updateOpenTime();
                }
                this._fastGuild.htmlText = HTMLUtil.addColor(Language.getString(60411), "#FFFF00") + HTMLUtil.addColor(this._info.bestGuildName != "" ? this._info.bestGuildName + "（" + RemainTimeTool.getRemainTimeBySeconds(this._info.bestGuildTime) + "）" : Language.getString(60418), "#FF00FF");
                this._tips.htmlText = HTMLUtil.addColor(Language.getString(60413), "#FFFF00") + "\n" + this._config.desc;
            }
            this.resize();
            return;
        }

        public updateExp(): void
        {
            this._expLabel.htmlText = HTMLUtil.addColor(Language.getStringByParam(60427, Cache.instance.copy.guildCopyExp), GlobalStyle.color5);
            return;
        }

        public updateContribute(): void
        {
            this._contribution.htmlText = HTMLUtil.addColor(Language.getStringByParam(60428, Cache.instance.copy.guildCopyContribution), GlobalStyle.color5);
            return;
        }

        public updateProcessInfo(arg1: SGuildStruggleProcess): void
        {
            this._process = arg1;
            this.updateProcess();
            this.resize();
            return;
        }

        /* internal */ /* var */_info: SGuildStruggleInfo;

        /* internal */ /* var */_process: SGuildStruggleProcess;

        /* internal */ /* var */_modeLabel: GTextFiled;

        /* internal */ /* var */_timeLabel: GTextFiled;

        /* internal */ /* var */_fastGuild: GTextFiled;

        /* internal */ /* var */_condition: GTextFiled;

        /* internal */ /* var */_expLabel: GTextFiled;

        /* internal */ /* var */_contribution: GTextFiled;

        /* internal */ /* var */_tips: GTextFiled;

        /* internal */ /* var */_openTimer: SecTimer;

        /* internal */ /* var */_leftTimer: SecTimer;

        /* internal */ /* var */_leftTime: int;

        /* internal */ /* var */_config: TGuildStruggleConfig;
    }
